USE [FootballPoll]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Votes_Teams]') AND parent_object_id = OBJECT_ID(N'[dbo].[Votes]'))
ALTER TABLE [dbo].[Votes] DROP CONSTRAINT [FK_Votes_Teams]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Votes_Users]') AND parent_object_id = OBJECT_ID(N'[dbo].[Votes]'))
ALTER TABLE [dbo].[Votes] DROP CONSTRAINT [FK_Votes_Users]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Votes_VoteSource]') AND parent_object_id = OBJECT_ID(N'[dbo].[Votes]'))
ALTER TABLE [dbo].[Votes] DROP CONSTRAINT [FK_Votes_VoteSource]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_Votes_FirstPlaceVotes]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[Votes] DROP CONSTRAINT [DF_Votes_FirstPlaceVotes]
END

GO

USE [FootballPoll]
GO

/****** Object:  Table [dbo].[Votes]    Script Date: 12/02/2011 13:29:29 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Votes]') AND type in (N'U'))
DROP TABLE [dbo].[Votes]
GO

USE [FootballPoll]
GO

/****** Object:  Table [dbo].[Votes]    Script Date: 12/02/2011 13:29:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Votes](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[teamID] [int] NOT NULL,
	[Points] [int] NOT NULL,
	[UserID] [int] NOT NULL,
	[Date] [datetime] NOT NULL,
	[FirstPlaceVotes] [int] NOT NULL,
	[VoteSourceID] [int] NULL,
 CONSTRAINT [PK_Votes] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[Votes]  WITH CHECK ADD  CONSTRAINT [FK_Votes_Teams] FOREIGN KEY([teamID])
REFERENCES [dbo].[Teams] ([id])
GO

ALTER TABLE [dbo].[Votes] CHECK CONSTRAINT [FK_Votes_Teams]
GO

ALTER TABLE [dbo].[Votes]  WITH CHECK ADD  CONSTRAINT [FK_Votes_Users] FOREIGN KEY([UserID])
REFERENCES [dbo].[Users] ([id])
GO

ALTER TABLE [dbo].[Votes] CHECK CONSTRAINT [FK_Votes_Users]
GO

ALTER TABLE [dbo].[Votes]  WITH CHECK ADD  CONSTRAINT [FK_Votes_VoteSource] FOREIGN KEY([VoteSourceID])
REFERENCES [dbo].[VoteSource] ([id])
GO

ALTER TABLE [dbo].[Votes] CHECK CONSTRAINT [FK_Votes_VoteSource]
GO

ALTER TABLE [dbo].[Votes] ADD  CONSTRAINT [DF_Votes_FirstPlaceVotes]  DEFAULT ((0)) FOR [FirstPlaceVotes]
GO

